import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
//import './assets/theme/theme-green/index.css'
import VueRouter from 'vue-router'
import store from './vuex/store'
import Vuex from 'vuex'
//import NProgress from 'nprogress'
//import 'nprogress/nprogress.css'
import routes from './routes'
/*import Mock from './mock'
Mock.bootstrap();*/
import 'font-awesome/css/font-awesome.min.css'




Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(Vuex)

//NProgress.configure({ showSpinner: false });

import axios from 'axios'
axios.defaults.baseURL="http://localhost:8080"
//========================axios拦截器==
//前置拦截器
axios.interceptors.request.use(config=>{
    //携带token
    let uToken =  localStorage.getItem("token");
    if(uToken){
        config.headers['token']=uToken;
    }
    return config;//一定要返回配置信息
},error => {
    Promise.reject(error);
});

//后置拦截器
axios.interceptors.response.use(result=>{
    console.log(result.data+"jjjjjjj");
    let data = result.data;
    if(!data.success && data.message==="noLogin"){
        localStorage.removeItem("token");
        localStorage.removeItem("logininfo");
        router.push({ path: '/login' });
    }
    return result;
},error => {
    Promise.reject(error);
});
//========================axios拦截器===
//axios.defaults.baseURL="/api"
Vue.prototype.$http=axios

const router = new VueRouter({
    routes
})

//路由前置拦截器  拦截静态资源
// router.beforeEach((to, from, next) => {//拦截器
//     //直接放行需要放行的静态资源
//     if (to.path == '/login' || to.path == '/shopRegister') {
//         localStorage.removeItem("token");
//         localStorage.removeItem("logininfo");
//         next();
//     }else{
//         //如果不是需要放行的静态资源，需要判断是否登录
//         let user = localStorage.getItem('logininfo');
//         if(!user){
//             //没有登录，跳转到登录页
//             next({ path: '/login' })
//         }else{
//             next();
//         }
//     }
// })

//router.afterEach(transition => {
//NProgress.done();
//});

new Vue({
    //el: '#app',
    //template: '<App/>',
    router,
    store,
    //components: { App }
    render: h => h(App)
}).$mount('#app')

